package cc.rengu.redp.bizimpl.csmc.service.impl;

import cc.rengu.redp.bizimpl.csmc.dao.ReconSceneInfoMapper;
import cc.rengu.redp.bizimpl.csmc.domain.ReconSceneInfo;
import cc.rengu.redp.bizimpl.csmc.service.IReconSceneInfoService;
import cc.rengu.redp.bizimpl.csmc.vo.ReconSceneInfoVO;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author System
 */
@DS("csmc")
@Slf4j
@Service("reconSceneInfoService")
public class ReconSceneInfoServiceImpl extends ServiceImpl<ReconSceneInfoMapper, ReconSceneInfo> implements IReconSceneInfoService {
    @Override
    public Map<String, Object> findByPage(String reconSceneId, String instId){

        Map<String, Object> result = new HashMap<>();
        if(StringUtils.isEmpty(reconSceneId)){
            log.warn("获取对账场景信息列表失败：参数对账场景标识为空");
            result.put("rows", null);
            result.put("total", 0);
            return result;
        }
        try {
            ReconSceneInfo reconScene = new ReconSceneInfo();
            reconScene.setReconSceneId(reconSceneId);
            reconScene.setInstId(instId);
            List<ReconSceneInfoVO> list = findList(reconScene);
            result.put("rows", list);
            result.put("total", CollectionUtils.isEmpty(list)?0:list.size());
        } catch (Exception e) {
            log.error("获取对账场景信息列表失败", e);
            result.put("rows", null);
            result.put("total", 0);
        }
        return result;
    }

    public List<ReconSceneInfoVO> findList(ReconSceneInfo reconScene){
        try {
            return this.baseMapper.findList(reconScene);
        } catch (Exception e) {
            log.error("查询用户异常", e);
            return null;
        }
    }
}
